#include "main.h"

#include <sfse_common/BranchTrampoline.h>

#include "Hook_Scaleform.h"

SFSEMessagingInterface* g_messaging = nullptr;

void MessageCallback(SFSEMessagingInterface::Message* msg)
{
    switch (msg->type)
    {
    case SFSEMessagingInterface::kMessage_PostPostLoad:
        _MESSAGE("postpostload");
        break;
    }
}

extern "C"
{
    __declspec(dllexport) SFSEPluginVersionData SFSEPlugin_Version =
    {
        SFSEPluginVersionData::kVersion,	
        1,
        "template",
        "Neanka",
        0,	// not address independent
        0,	// not structure independent
        { CURRENT_RELEASE_RUNTIME, 0},	// compatible with 1.7.23 and that's it
        0,	// works with any version of the script extender. you probably do not need to put anything here
        0, 0,	// set these reserved fields to 0
    };

    __declspec(dllexport) bool SFSEPlugin_Load(const SFSEInterface *sfse)
    {
        DebugLog::openRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Starfield\\SFSE\\Logs\\template.txt");
        _MESSAGE("load");

        g_messaging = static_cast<SFSEMessagingInterface*>(sfse->QueryInterface(kInterface_Messaging));
        if (!g_messaging)
        {
            _FATALERROR("couldn't get messaging interface");
            return false;
        }
        g_messaging->RegisterListener(sfse->GetPluginHandle(), "SFSE", MessageCallback);
        
        if (!g_branchTrampoline.create(1024 * 64))
        {
            _ERROR("couldn't create branch trampoline. this is fatal. skipping remainder of init process.");
            return false;
        }

        if (!g_localTrampoline.create(1024 * 64, nullptr))
        {
            _ERROR("couldn't create codegen buffer. this is fatal. skipping remainder of init process.");
            return false;
        }
        Hooks_Scaleform_Apply();
        return true;
    }
};
